package com.rookie.redis.module.config;

import org.redisson.Redisson;
import org.redisson.api.RMapCache;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.IntegerCodec;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author rookie
 */
@Configuration
public class RedissonManagerConfig {

    @Bean(name = "redissonClient")
    public static RedissonClient redissonClientSingle(){
        RedissonClient redisson = null;
        Config config = new Config();
        config.useSingleServer()
			.setAddress("redis://" + "127.0.0.1" + ":" + "6379");
        redisson = Redisson.create(config);
        return redisson;
    }

    public static void main(String[] args) {
        RedissonClient redissonClient = redissonClientSingle();
        RMapCache<Object, Object> nameSpace = redissonClient.getMapCache("nameSpace", IntegerCodec.INSTANCE);
        System.out.println(nameSpace.addAndGet("test", 1));
    }
}
